package Algorithm.Othes;

//https://leetcode-cn.com/problems/day-of-the-year/
//1154. 一年中的第几天
public class Leetcode1154 {
    class Solution {
        public int dayOfYear(String date) {
            int year = Integer.parseInt(date.substring(0, 4));
            int month = Integer.parseInt(date.substring(5, 7));
            int day = Integer.parseInt(date.substring(8));

            int[] amount = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                ++amount[1];
            }

            int ans = 0;
            for (int i = 0; i < month - 1; ++i) {
                ans += amount[i];
            }
            return ans + day;
        }
    }
}
